//
//  SceneDelegate.m
//  iosFramework
//
//  Created by Farben on 2020/8/4.
//  Copyright © 2020 Farben. All rights reserved.
//

#import "SceneDelegate.h"
#import "ZJRTRootNavigationController.h"
#import "ZJTabBarViewController.h"
#import <AvoidCrash/AvoidCrash.h>
#import <Bugly/Bugly.h>
#import "ZJMacroFile.h"
#import "SceneDelegate+ZJ.h"
#import "JLRoutes.h"


@interface SceneDelegate ()

@end

@implementation SceneDelegate


- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
    
    if (@available(iOS 13.0, *)) {
        UIWindowScene *windowScene = (UIWindowScene *)scene;
        self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
        self.window.frame = windowScene.coordinateSpace.bounds;
        
        self.window.rootViewController = [[ZJTabBarViewController alloc] init];
        [self.window makeKeyAndVisible];
    } else {
        // Fallback on earlier versions
        UIWindowScene *windowScene = (UIWindowScene *)scene;
        self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
        self.window.frame = windowScene.coordinateSpace.bounds;
        
        self.window.rootViewController = [[ZJTabBarViewController alloc] init];
        [self.window makeKeyAndVisible];
    }
    
    NSSetUncaughtExceptionHandler(&getException);
    
    [self startAvoidCrash];
    
    [self initBugly];
    
}

#pragma mark - 崩溃获取
void getException(NSException *exception)
{
    DLog(@"名字：%@",exception.name);
    DLog(@"原因：%@",exception.reason);
    DLog(@"用户信息：%@",exception.userInfo);
    DLog(@"栈内存地址：%@",exception.callStackReturnAddresses);
    DLog(@"栈描述：%@",exception.callStackSymbols);
}


- (void)sceneDidDisconnect:(UIScene *)scene {
    
}


- (void)sceneDidBecomeActive:(UIScene *)scene {
    // Called when the scene has moved from an inactive state to an active state.
    // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
}


- (void)sceneWillResignActive:(UIScene *)scene {
    // Called when the scene will move from an active state to an inactive state.
    // This may occur due to temporary interruptions (ex. an incoming phone call).
}


- (void)sceneWillEnterForeground:(UIScene *)scene {
    // Called as the scene transitions from the background to the foreground.
    // Use this method to undo the changes made on entering the background.
}


- (void)sceneDidEnterBackground:(UIScene *)scene {
    // Called as the scene transitions from the foreground to the background.
    // Use this method to save data, release shared resources, and store enough scene-specific state information
    // to restore the scene back to its current state.
}


/*
 Route的代码
 // navigation Push规则
  [[JLRoutes globalRoutes] addRoute:@"/NaviPush/:controller" handler:^BOOL(NSDictionary<NSString *,NSString *> * _Nonnull parameters) {
      
      NSLog(@"parameters==%@",parameters);
      UIViewController *v = [[NSClassFromString(parameters[@"controller"]) alloc] init];
      [self paramToVc:v param:parameters];
      [[self currentViewController] pushViewController:v animated:YES];
      return YES;
  }];
  
  
  // 模态窗口规则
  [[JLRoutes globalRoutes] addRoute:@"/PresentModal/:controller" handler:^BOOL(NSDictionary<NSString *,NSString *> * _Nonnull parameters) {
      
      NSLog(@"parameters==%@",parameters);
      UIViewController *v = [[NSClassFromString(parameters[@"controller"]) alloc] init];
      [self paramToVc:v param:parameters];
      [[self currentViewController].visibleViewController presentViewController:v animated:YES completion:^{}];
      return YES;
  }];
  
 */


@end

